//
//  LzwAdressView.m
//  NewHalfsugar
//
//  Created by 刘志武 on 16/1/13.
//  Copyright © 2016年 刘志武. All rights reserved.
//

#import "LzwAdressView.h"
#import "LzwBaseImageView.h"
#import "UIImageView+WebCache.h"


@interface LzwAdressView ()

@property (nonatomic, retain) LzwBaseImageView *myAddressImage1;
@property (nonatomic, retain) LzwBaseImageView *myAddressImage2;
@property (nonatomic, retain) LzwBaseImageView *myAddressImage3;
@property (nonatomic, retain) LzwBaseImageView *myAddressImage4;


@end

@implementation LzwAdressView

-(void)dealloc{
    [_myAddressImage1 release];
    [_myAddressImage2 release];
    [_myAddressImage3 release];
    [_myAddressImage4 release];
    [super dealloc];
    
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {
    }
    return self;
}

-(void)setArray:(NSMutableArray *)array{
    
    if (_array != array) {
        [_array release];
        _array = [array retain];
    }
    
    [self creatAdressViews];
    
}

- (void)creatAdressViews{
    
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(aaaaa:)];
    
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(bbbbb:)];
    
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ccccc:)];
    
    
    UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(ddddd:)];
    
    
    
    self.myAddressImage1 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(0, 0, 215 * WIDTH, 220 * WIDTH)];
    self.myAddressImage1.userInteractionEnabled = YES;
    [self.myAddressImage1 addGestureRecognizer:tap1];
    //    self.myAddressImage1.backgroundColor = [UIColor lightGrayColor];
    self.myAddressImage1.tag = 20001;
    [self addSubview:self.myAddressImage1];
    
    self.myAddressImage2 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(216 * WIDTH, 0, 159 * WIDTH, 139 * WIDTH)];
    //    self.myAddressImage2.backgroundColor = [UIColor greenColor];
    self.myAddressImage2.userInteractionEnabled = YES;
    
    [self.myAddressImage2 addGestureRecognizer:tap2];
    self.myAddressImage2.tag = 20002;

    [self addSubview:self.myAddressImage2];
    
    self.myAddressImage3 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(216 * WIDTH, 140 * WIDTH, 79 * WIDTH, 80 * WIDTH)];
    //    self.myAddressImage3.backgroundColor = [UIColor redColor];
    self.myAddressImage3.userInteractionEnabled = YES;
    [self.myAddressImage3 addGestureRecognizer:tap3];
    self.myAddressImage3.tag = 20003;

    [self addSubview:self.myAddressImage3];
    
    self.myAddressImage4 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(296 * WIDTH, 140 * WIDTH, 80 * WIDTH, 79 * WIDTH)];
    //    self.myAddressImage4.backgroundColor = [UIColor orangeColor];
    self.myAddressImage4.userInteractionEnabled = YES;
    [self.myAddressImage4 addGestureRecognizer:tap4];
    self.myAddressImage4.tag = 20004;

    [self addSubview:self.myAddressImage4];
    
    LzwAdressModle *modle1 = [self.array objectAtIndex:0];
    
    NSURL *url1 = [NSURL URLWithString:modle1.pic1];
    
    [self.myAddressImage1 sd_setImageWithURL:url1 placeholderImage:nil];
    
    LzwAdressModle *modle2 = [self.array objectAtIndex:1];
    
    NSURL *url2 = [NSURL URLWithString:modle2.pic1];
    
    [self.myAddressImage2 sd_setImageWithURL:url2 placeholderImage:nil];
    
    
    LzwAdressModle *modle3 = [self.array objectAtIndex:2];
    
    NSURL *url3 = [NSURL URLWithString:modle3.pic1];
    
    [self.myAddressImage3 sd_setImageWithURL:url3 placeholderImage:nil];
    
    LzwAdressModle *modle4 = [self.array objectAtIndex:3];
    
    NSURL *url4 = [NSURL URLWithString:modle4.pic1];
    
    [self.myAddressImage4 sd_setImageWithURL:url4 placeholderImage:nil];
    
    [_myAddressImage1 release];
    [_myAddressImage2 release];
    [_myAddressImage3 release];
    [_myAddressImage4 release];
    
    
    
}

- (void)aaaaa:(UITapGestureRecognizer *)aa{
    [self.myAdressViewDelegata pushDtailPage:self.myAddressImage1.tag];
}
- (void)bbbbb:(UITapGestureRecognizer *)bb{

    [self.myAdressViewDelegata pushDtailPage:self.myAddressImage2.tag];
}
- (void)ccccc:(UITapGestureRecognizer *)cc{
    [self.myAdressViewDelegata pushDtailPage:self.myAddressImage3.tag];
}
- (void)ddddd:(UITapGestureRecognizer *)dd{
    [self.myAdressViewDelegata pushDtailPage:self.myAddressImage4.tag];
}



@end
